package org.osforce.platform.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 
 * @author gavin
 * 
 */
@Entity
@Table(name="categories")
public class Category extends IdEntity{

	private static final long serialVersionUID=5703807637662034512L;

	private String name;
	private String scope;
	private Boolean root=Boolean.FALSE;
	private Boolean leaf=Boolean.FALSE;

	private Category parent;
	private Set<Category> children=new HashSet<Category>();

	public Category(){
	}

	@Column(name="name",length=50,nullable=false)
	public String getName(){
		return name;
	}

	public void setName(String name){
		this.name=name;
	}

	@Column(name="scope",length=50,nullable=false)
	public String getScope(){
		return scope;
	}

	public void setScope(String scope){
		this.scope=scope;
	}

	@Column(name="root",nullable=false)
	public Boolean getRoot(){
		return root;
	}

	public void setRoot(Boolean root){
		this.root=root;
	}

	@Column(name="leaf",nullable=false)
	public Boolean getLeaf(){
		return leaf;
	}

	public void setLeaf(Boolean leaf){
		this.leaf=leaf;
	}
	@ManyToOne
	@JoinColumn(name="pid")
	public Category getParent(){
		return parent;
	}

	public void setParent(Category parent){
		this.parent=parent;
	}

	@OneToMany(cascade={CascadeType.ALL},mappedBy="parent")
	public Set<Category> getChildren(){
		return children;
	}

	public void setChildren(Set<Category> children){
		this.children=children;
	}

}
